package com.polaris.live.adapter

import android.annotation.SuppressLint
import androidx.appcompat.widget.AppCompatTextView
import com.blankj.utilcode.util.StringUtils
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.polaris.live.R
import com.polaris.live.im.sfs.MESSAGE_GREET_0
import com.polaris.live.im.sfs.MESSAGE_GREET_1
import com.polaris.live.im.sfs.MESSAGE_GREET_2
import com.polaris.live.im.sfs.MESSAGE_GREET_3
import com.polaris.live.im.sfs.bean.chat.GreetMessage
import com.polaris.live.translation.R.*
import com.polaris.live.utils.image.ImageUtils
import com.polaris.live.utils.image.normal

/**
 * MessageGreetAdapter
 *
 * @author Created by 长空 on 2023/10/24/013 10:24
 */
class MessageGreetAdapter : BaseMultiItemQuickAdapter<GreetMessage, BaseViewHolder>() {

    private var size: Int = 0

    init {
        addItemType(MESSAGE_GREET_0, R.layout.item_message_greet_review)
        addItemType(MESSAGE_GREET_1, R.layout.item_message_greet_success)
        addItemType(MESSAGE_GREET_2, R.layout.item_message_greet_failure)
        addItemType(MESSAGE_GREET_3, R.layout.item_message_greet_upload)
    }

    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: GreetMessage) {
        when (holder.itemViewType) {
            MESSAGE_GREET_0 -> {//审核中
                Glide.with(context)
                    .load(ImageUtils.imgPathMiddle(item.photoUrl))
                    .normal()
                    .into(holder.getView(R.id.iv_avatar))
                holder.getView<AppCompatTextView>(R.id.tv_message).text = item.content
            }

            MESSAGE_GREET_1 -> {//审核成功
                Glide.with(context)
                    .load(ImageUtils.imgPathMiddle(item.photoUrl))
                    .normal()
                    .into(holder.getView(R.id.iv_avatar))
                holder.getView<AppCompatTextView>(R.id.tv_message).text = item.content
                holder.getView<AppCompatTextView>(R.id.tv_push_num).text =
                    item.stat?.pushedNumber.toString()
                holder.getView<AppCompatTextView>(R.id.tv_receive_num).text =
                    item.stat?.replyNumber.toString()
                holder.getView<AppCompatTextView>(R.id.tv_push).text =
                    "${StringUtils.getString(string.message_greet_pushed)}: "
                holder.getView<AppCompatTextView>(R.id.tv_receive).text =
                    "${StringUtils.getString(string.message_greet_receive)}: "
            }

            MESSAGE_GREET_2 -> {//审核失败
                Glide.with(context)
                    .load(ImageUtils.imgPathMiddle(item.photoUrl))
                    .normal()
                    .into(holder.getView(R.id.iv_avatar))
                holder.getView<AppCompatTextView>(R.id.tv_message).text = item.content
            }

            MESSAGE_GREET_3 -> {//上传模板
                holder.setText(R.id.tv_num, "${size}/3")
            }
        }
    }

    fun setDataSize(size: Int) {
        this.size = size
    }

}